<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('电费管理列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
<!--                        <li>-->
<!--                            <label>项目名称：</label>-->
<!--                            <select name="projectId" id="projectId" class="form-control m-b"  >-->
<!--                                <option value="" >所有</option>-->
<!--                                <option th:each="SysProject:${sysProjects}" th:text="${SysProject.projectName}" th:value="${SysProject.projectId}"></option>-->
<!--                            </select>-->
<!--                        </li>-->
                        <li>
                            <label>项目名称：</label>
                            <input type="text" name="projectName"/>
                        </li>
                        <li>
                            <label>租户楼层：</label>
                            <input type="text" name="floorName"/>
                        </li>
						<li>
						    <label>房间号：</label>
						    <input type="text" name="roomNumber"/>
						</li>
						<li>
						    <label>单位名称：</label>
						    <input type="text" name="companyName"/>
						</li>
<!--                        <li>-->
<!--                            <label>电费月份：</label>-->
<!--                            <input type="text" name="elecMonth"/>-->
<!--                            <select class="form-control" name="elecMonth">-->
<!--                                <option value="">所有</option>-->
<!--                                <option value="1月">1月</option>-->
<!--                                <option value="2月">2月</option>-->
<!--                                <option value="3月">3月</option>-->
<!--                                <option value="4月">4月</option>-->
<!--                                <option value="5月">5月</option>-->
<!--                                <option value="6月">6月</option>-->
<!--                                <option value="7月">7月</option>-->
<!--                                <option value="8月">8月</option>-->
<!--                                <option value="9月">9月</option>-->
<!--                                <option value="10月">10月</option>-->
<!--                                <option value="11月">11月</option>-->
<!--                                <option value="12月">12月</option>-->

<!--                            </select>-->
<!--                        </li>-->
                        <li>
                            <label>电费月份：</label>
                            <div class="input-daterange input-group">
                                <input type="text" name="elecMonthBegin" placeholder="请填写月份"/>
                                <span>&nbsp;到&nbsp;</span>
                                <input type="text" name="elecMonthOver" placeholder="请填写月份"/>
                            </div>
                        </li>
<!--						<li>-->
<!--						    <label>房屋单价：</label>-->
<!--						    <input type="text" name="tenantPrice"/>-->
<!--						</li>-->
<!--                        <li>-->
<!--                            <label>租赁开始时间：</label>-->
<!--                            <input type="text" class="time-input" placeholder="请选择租赁开始时间" name="tenantTime"/>-->
<!--                        </li>-->
<!--                        <li>-->
<!--                            <label>租赁到期时间：</label>-->
<!--                            <input type="text" class="time-input" placeholder="请选择租赁到期时间" name="tenantEndTime"/>-->
<!--                        </li>-->
<!--                        <li>-->
<!--                            <label>付款方式：</label>-->
<!--                            <input type="text" name="chargesType"/>-->
<!--                        </li>-->
<!--                        <li>-->
<!--                            <label>状态：</label>-->
<!--                            <select name="tenantStatus">-->
<!--                                <option value="">所有</option>-->
<!--                                <option value="0">正常</option>-->
<!--                                <option value="1">临期</option>-->
<!--                                <option value="2">到期</option>-->
<!--                                <option value="3">异常</option>-->
<!--                            </select>-->
<!--                        </li>-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="query()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="property:elecCost:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="property:elecCost:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="property:elecCost:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-success" onclick="importExcel()" shiro:hasPermission="property:elecCost:import">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="allExportExcel()" shiro:hasPermission="property:elecCost:meterExport">
                <i class="fa fa-download"></i> 月度抄表导出
            </a>
            <a class="btn btn-warning" onclick="leaderExportExcel()" shiro:hasPermission="property:elecCost:unitsExport">
                <i class="fa fa-download"></i> 月度单位导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('property:elecCost:edit')}]];
    var removeFlag = [[${@permission.hasPermi('property:elecCost:remove')}]];
    var prefix = ctx + "guomao/elecCostManagement";
    var options;
    //var eleMonth;
    function query() {
        if (options != null && options != undefined) {
            var params = $("#bootstrap-table").bootstrapTable('getOptions');
            $("#bootstrap-table").bootstrapTable('refresh', params);
        } else {
            options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                leaderExportUrl: prefix + "/leaderExport",
                allExportUrl: prefix + "/allExport",
                importUrl: prefix + "/import",
                importTemplateUrl: prefix + "/importTemplate",
                uniqueId: "elecCostId",
                modalName: "租户管理",
                sortName: "serialNumber",
                sortOrder: "asc",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'serialNumber',
                        title: '序号',
                    },
                    {
                        field: 'elecCostId',
                        title: '电费编号',
                        visible: false
                    },
                    {
                        field: 'projectName',
                        title: '项目名称'
                    },
                    {
                        field: 'floorName',
                        title: '楼层号'
                    },
                    {
                        field: 'roomNumber',
                        title: '房间号'
                    },
                    {
                        field: 'companyName',
                        title: '单位名称'
                    },
                    {
                        field: 'checkMeterNumber',
                        title: '表号'
                    },
                    {
                        field: 'degreePreA',
                        title: '上月A电表',
                        visible: false
                    },
                    {
                        field: 'degreeIssueA',
                        title: '本月A电表',
                        visible: false
                    },
                    {
                        field: 'degreeA',
                        title: '本月A实用电量',
                        visible: false
                    },
                    {
                        field: 'degreePreB',
                        title: '上月B电表',
                        visible: false
                    },
                    {
                        field: 'degreeIssueB',
                        title: '本月B电表',
                        visible: false
                    },
                    {
                        field: 'degreeB',
                        title: '本月B实用电量',
                        visible: false
                    },
                    {
                        field: 'degreePreC',
                        title: '上月C电表',
                        visible: false
                    },
                    {
                        field: 'degreeIssueC',
                        title: '本月C电表',
                        visible: false
                    },
                    {
                        field: 'degreeC',
                        title: '本月C实用电量',
                        visible: false
                    },
                    {
                        field: 'degreePreD',
                        title: '上月D电表',
                        visible: false
                    },
                    {
                        field: 'degreeIssueD',
                        title: '本月D电表',
                        visible: false
                    },
                    {
                        field: 'degreeD',
                        title: '本月D实用电量',
                        visible: false
                    },
                    {
                        field: 'degreePre',
                        title: '上月度数和',
                        visible: false
                    },
                    {
                        field: 'degreeIssue',
                        title: '本月度数和',
                        visible: false
                    },
                    {
                        field: 'degree',
                        title: '本月总用电量'
                    },
                    {
                        field: 'elecRate',
                        title: '电费乘率'
                    },
                    {
                        field: 'elecUnitPrice',
                        title: '电费单价'
                    },
                    {
                        field: 'elecTotalPrice',
                        title: '电费总价'
                    },
                    {
                        field: 'elecMonth',
                        title: '电费月份'
                    },
                    {
                        field: 'checkMeterTime',
                        title: '抄表时间'
                    },
                    // {
                    //     field: 'tenantTerm',
                    //     title: '租赁期限（年）'
                    // },
                    // {
                    //     field: 'tenantStatus',
                    //     title: '状态',
                    //     formatter: function(value, row, index) {
                    //         if(row.tenantStatus=="0"){
                    //             return '<span class="label label-primary">正常</span>';
                    //         }else if(row.tenantStatus=="1"){
                    //             return '<span class="label label-success">临期</span>';
                    //         } else if(row.tenantStatus=="2"){
                    //             return '<span class="label label-warning">到期</span>';
                    //         } else {
                    //             return '<span class="label label-danger">异常</span>';
                    //         }
                    //     }
                    // },
                    {
                        field: 'remark',
                        title: '信息备注'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.elecCostId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.elecCostId + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        }
    }
    /*导出接口*/
    /**
    function exportExcel(){
        var rows=$.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        };
        $.modal.confirm("确认要导出选中的" + rows.length + "条数据吗?", function() {
            var url = table.options.exportUrl;
            var data = { "ids": rows.join() };
            $.modal.loading("正在导出数据，请稍后...");
            $.post(url,data,function (res) {
                if (res.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(res.msg) + "&delete=" + true;
                } else if (res.code == web_status.WARNING) {
                    $.modal.alertWarning(res.msg)
                } else {
                    $.modal.alertError(res.msg);
                }
                $.modal.closeLoading();
            })
        });
    }
*/

    function leaderExportExcel() {
        layer.open({
            type:1,
            title:["选择导出的电费月份","font-size:18px"],
            area:["400px","180px"],
            shade:false,
            anim:3,
            shade:0.3,
            content:$("#checkMonth").html(),
            btn:['确认'],
            yes:function () {
                var month = $('#insertMonth').val();
                var reg = /^\b[1-3]\d{3}(0[1-9]|1[0-2])$/;
                if(month==null||month==""||month==undefined){
                    $.modal.alertError("请输入电费的年月")
                    return;
                }else if(month.match(reg) == null){
                    $.modal.alertError("请确认电费的年月格式")
                    return;
                }
                $.modal.confirm("确认要导出选中的" + month + "月数据吗?", function() {
                    var url = table.options.leaderExportUrl;
                    var data = { "elecMonth": month};
                    $.modal.loading("正在导出数据，请稍后...");
                    $.post(url,data,function (res) {
                        if (res.code == web_status.SUCCESS) {
                            window.location.href = ctx + "common/download?fileName=" + encodeURI(res.msg) + "&delete=" + true;
                        } else if (res.code == web_status.WARNING) {
                            $.modal.alertWarning(res.msg)
                        } else {
                            $.modal.alertError(res.msg);
                        }
                        $.modal.closeLoading();
                        layer.closeAll();
                    })
                });
            }
        })
    }

    function allExportExcel() {
        layer.open({
            type:1,
            title:["选择导出的电费月份","font-size:18px"],
            area:["400px","180px"],
            shade:false,
            anim:3,
            shade:0.3,
            content:$("#checkMonth").html(),
            btn:['确认'],
            yes:function () {
                var month = $('#insertMonth').val();
                var reg = /^\b[1-3]\d{3}(0[1-9]|1[0-2])$/;
                if(month==null||month==""||month==undefined){
                    $.modal.alertError("请输入电费的年月")
                    return;
                }else if(month.match(reg) == null){
                    $.modal.alertError("请确认电费的年月格式")
                    return;
                }
                $.modal.confirm("确认要导出选中的" + month + "月数据吗?", function() {
                    var url = table.options.allExportUrl;
                    var data = { "elecMonth": month };
                    $.modal.loading("正在导出数据，请稍后...");
                    $.post(url,data,function (res) {
                        if (res.code == web_status.SUCCESS) {
                            window.location.href = ctx + "common/download?fileName=" + encodeURI(res.msg) + "&delete=" + true;
                        } else if (res.code == web_status.WARNING) {
                            $.modal.alertWarning(res.msg)
                        } else {
                            $.modal.alertError(res.msg);
                        }
                        $.modal.closeLoading();
                        layer.closeAll();
                    })
                });
            }
        })

    }

    /**
     * 导入
     * */
    function importExcel(formId, width, height) {
        table.set();
        var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
        var _width = $.common.isEmpty(width) ? "400" : width;
        var _height = $.common.isEmpty(height) ? "230" : height;
        layer.open({
            type: 1,
            area: [_width + 'px', _height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: '导入' + table.options.modalName + '数据',
            content: $('#' + currentId).html(),
            btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
            // 弹层外区域关闭
            shadeClose: true,
            btn1: function(index, layero){
                var file = layero.find('#drfile').val();
                if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))){
                    $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
                    return false;
                }
                var index = layer.load(2, {shade: false});
                $.modal.disable();
                var formData = new FormData(layero.find('form')[0]);
                $.ajax({
                    url:prefix + "/importExcel",
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    type: 'POST',
                    success: function (result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.closeAll();
                            $.modal.alertSuccess(result.msg);
                            $.table.refresh();
                        } else if (result.code == web_status.WARNING) {
                            layer.close(index);
                            $.modal.enable();
                            $.modal.alertWarning(result.msg)
                        } else {
                            layer.close(index);
                            $.modal.enable();
                            $.modal.alertError(result.msg);
                        }
                    }
                });
            }
        });
    }

</script>
</body>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="drfile" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果参数已经存在，更新这条数据。"> 是否更新已经存在的参数数据
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs" shiro:hasPermission="property:elecCost:template"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件，导入的月份以第一行月份批次为准！！！
            </font>
        </div>
    </form>
</script>

<!-- 月份选择 -->
<script type="text/template" id="checkMonth">
    <form class="mt20 mb10">
        <div style="margin: 20px;">
            <span style="color: red;">请输入要导出的电费月份（yyyyMM，例202101）</span>
            <input type="text" class="form-control" id="insertMonth" >
        </div>
    </form>
</script>

</html>